package com.sztz.design.buildprototype;

import cn.hutool.json.JSONUtil;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.io.Serializable;
import java.util.Date;

/**
 * 浅拷贝对象
 * @author yzy
 * @date 2022/8/31 19:14
 */
@Data
@Slf4j
public class ShallowUser implements Cloneable,Serializable {
    private String name;
    private String code;
    private Integer age;
    private Date birth;
    @Override
    public Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    public static void main(String[] args) throws CloneNotSupportedException {
        ShallowUser user = new ShallowUser();
        user.setName("浅浅");
        user.setAge(18);
        user.setCode("QianObj");
        user.setBirth(new Date());

        ShallowUser newUser = (ShallowUser)user.clone();
        newUser.setAge(20);
        long time = System.currentTimeMillis()+1000;
        newUser.getBirth().setTime(time);
        log.info("user = {}", JSONUtil.toJsonStr(user));
        log.info("clone user = {}",JSONUtil.toJsonStr(newUser));

    }
}
